package com.dao.impl;

import com.bean.Admin;
import com.dao.AdminDao;
import com.dao.BaseDao;

import java.util.List;

public class AdminDaoImpl extends BaseDao implements AdminDao {
    //管理员添加
    @Override
    public int addAdmin(Admin admin) {
        String sql= "INSERT INTO `admin`(`adminname`,`adminpassword`,`adminemail`,`adminPhone`,`adminpic`,`iroleId`)VALUES (?,?,?,?,?,?)";
        return update(sql,admin.getAdminname(),admin.getAdminpassword(),admin.getAdminemail(),admin.getAdminPhone(),admin.getAdminpic(),admin.getIroleId());
    }
//管理员删除
    @Override
    public int deleteAdminid(int id) {
        String sql="delete from `admin` where `id` =?";
        return update(sql, id);
    }
//管理员修改
    @Override
    public int updataAdmin(Admin admin) {
        String sql="update admin set  `adminname`=?,`adminpassword`=?,`adminemail`=?,`adminPhone`=?,`adminpic`=?,`iroleId`=?  WHERE `id`=? ";
        return update(sql,admin.getAdminemail(),admin.getAdminname(),admin.getAdminpassword(),admin.getAdminPhone(),admin.getAdminpic(),admin.getIroleId(),admin.getId());
    }
//管理员登录验证查询
    @Override
    public Admin queryAdminvname(String adminname, String adminpassword) {
        String sql= "SELECT `id`,`adminname`,`adminpassword`,`adminemail`,`adminPhone`,`adminpic`,`iroleId` from `admin` where `adminname`=? and `adminpassword`=?";
        return queryForOne(Admin.class,adminname,adminpassword);
    }
//通过名字查询管理员信息
    @Override
    public List<Admin>  queryAname(String adminname) {
        String sql= "SELECT `id`,`adminname`,`adminpassword`,`adminemail`,`adminPhone`,`adminpic`,`iroleId`from `admin` where `adminname`=? ";
        return queryForList(Admin.class,sql,adminname);
    }
//查找所有管理员的信息
    @Override
    public List<Admin> queryAdminAll() {
        String sql= "SELECT `id`,`adminname`,`adminpassword`,`adminemail`,`adminPhone`,`adminpic`,`iroleId` from `admin`";
        return queryForList(Admin.class,sql);
    }
}
